package io;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
通过提高每次读写的数据量减少实际读写的次数，可以提供写的效率
 */
public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("xiao.jpg");
        FileOutputStream fos = new FileOutputStream("xiao_p.jpg");

        /*

         */
        long start = System.currentTimeMillis();
        byte[] data = new byte[1024*10];
        int len;//记录每次实际读取的字节数
        while((len=fis.read(data))!=-1){//每次读取10kb并判断是否读取到末尾
            //将字节数组byte从下标0开始连续len个字节写出(做到读多少就写多少)
            fos.write(data,0,len);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕:"+(end-start)+"ms");

        fis.close();
        fos.close();



        /*
        long start = System.currentTimeMillis();
        byte[] data = new byte[1024*10];
        while(fis.read(data)!=-1){//每次读取10kb并判断是否读取到末尾
            fos.write(data);//一次写入10kb数据
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕:"+(end-start)+"ms");

        fis.close();
        fos.close();
         */


        FileInputStream f = new FileInputStream("xiao.jpg");
        FileOutputStream f1 = new FileOutputStream("xiao_o.jpg");
        long l = System.currentTimeMillis();
        byte[] b = new byte[1024*10];
        int len1;
        while((len1=f.read(b))!=-1){
            f1.write(b,0,len1);
        }
        long l1 = System.currentTimeMillis();
        System.out.println("消耗:"+(l1-l));
        System.out.println("复制成功");
        f.close();
        f1.close();







    }
}
